/*
 * @Author: your name
 * @Date: 2020-07-28 23:03:22
 * @LastEditTime: 2020-07-29 21:54:49
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \react-hooks-app\src\demo\colorState.js
 */

import React, { createContext,useReducer } from 'react';

export const ColorContext = createContext({})

export const UPDATE_COLOR = 'UPDATE_COLOR'

const colorStateDefault = {
  color:'blue',
  name:'hello',
  kkk:'ccc'
}
const colorReducer = (state,action)=>{
  switch (action.type) {
    case UPDATE_COLOR:
        return {...state,color:action.color}
    default:
      return state;
  }
}
export const ColorCom = (props)=>{

  const [colorState,dispatch] = useReducer(colorReducer,colorStateDefault)

  return (
    <ColorContext.Provider value={{...colorState,dispatch:dispatch}}>
      {props.children}
    </ColorContext.Provider>
  )
}


